﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;

namespace NHibernate.Expression.Extensions.Utils {
    public static class ExpressionExtensions {
        public static string MemberName<T, R>(this Expression<Func<T, R>> f) {
            var expr = f.Body as MemberExpression;
            if (expr == null) {
                var u = f.Body as UnaryExpression;
                expr = u.Operand as MemberExpression;
            }
            return expr.Member.Name;
        }

        public static IEnumerable<KeyValuePair<object, MemberInfo>> MemberPath(this System.Linq.Expressions.Expression exp) {
            var v = new MemberPathExpressionVisitor(exp);
            return v.MemberPath;
        }
    }
}